import request from '@/utils/request'

/**
 * 获取字典列表
 */
export const getDictionaryList = (data) => {
    
    return request({
        url: '/admin/dictionary_type/list',
        method: 'post',
        data
    })
}

/**
 * 新增字典
 */
export const addDictionary = (data) => {
    return request({
        url: '/admin/dictionary_type/add',
        method: 'post',
        data
    })
}

/**
 * 编辑字典
 */
export const updateDictionary = (data) => {
    return request({
        url: '/admin/dictionary_type/edit',
        method: 'post',
        data
    })
}




/**
 * 根据字典类型(typeKey)获取字典数据
 */
export const getDictionaryDataByTypeKey = (data) => {
    return request({
        url: '/admin/dictionary_data/list',
        method: 'post',
        data
    })
}

/**
 * 新增字典数据
 */
export const addDictionaryData = (data) => {
    return request({
        url: '/admin/dictionary_data/add',
        method: 'post',
        data
    })
}

/**
 * 编辑字典数据
 */
export const updateDictionaryData = (data) => {
    return request({
        url: '/admin/dictionary_data/edit',
        method: 'post',
        data
    })
}



/**
 * 删除字典类型
 */
export const deleteDictionaryType = (typeKey) => {
    return request({
        url: '/admin/dictionary_type/delete',
        method: 'get',
        params: { typeKey }
    })
}

/**
 * 删除字典数据
 */
export const deleteDictionaryData = (dataKey) => {
    return request({
        url: '/admin/dictionary_data/delete',
        method: 'get',
        params: { dataKey }
    })
}

/**
 * 获取字典数据的子级数量
 */
export const getDictionaryDataChildrenCount = (dataKey) => {
    return request({
        url: '/admin/dictionary_data/get_children_count',
        method: 'get',
        params: { dataKey }
    })
}


/**
 * 刷新字典数据到缓存
 */
export const refreshDictionaryCache = () => {
    return request({
        url: '/admin/dictionary_data/refresh',
        method: 'post'
    })
}

/**
 * 上传icon文件
 */
export const uploadIcon = (data) => {
    // 确保 FormData 包含 pathPrefix 参数
    if (data instanceof FormData) {
        data.append('pathPrefix', 'icons')
    }
    return request({
        url: '/file/file/upload',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}
